// 封装错误信息
function fail(thing) {
    throw new Error(thing);
}

// 封装警告信息
function warn(thing) {
    console.log(["WARNING:", thing].join(" "));
} 

// 封装一般提示信息
function note(thing) {
    console.log(["NOTE:", thing].join(" "));
}

// 转换年龄的函数
// age 为字符串类型
function parseAge(age) {
    if (typeof age !== 'string') fail("Expecting a string.")
    var a;
    note("Attempting to parse an age.")

    a = parseInt(age, 10);
    if (isNaN(a)) {
        warn(["Could not parse age:", age].join(" "))
        a = 0;
    }
    return a;
}

// parseAge(42);
// parseAge("42");
parseAge("abc");